/**
 * 神州信息(2012)
 */
package net.abbp.mtr;

import java.awt.EventQueue;
import java.awt.Font;
import java.util.Enumeration;

import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;

import net.abbp.dao.spring.manager.DataSourceManager;
import net.abbp.serial.SimpleSerial;
import net.abbp.sms.SmsSender;

import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.plaf.office2003.Office2003Painter;
import com.jidesoft.utils.SystemInfo;

/**
 * 设计器启动
 * 
 * @version 1.0
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ABBP 1.0
 * 
 *        Date：2012-4-1
 */
public class Starter {
    /**
     * 简单串口读写
     */
    public static SimpleSerial SERIAL;
    public static MainMtrWindow MAIN_FRAME;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                try {
                    Office2003Painter.setNative(SystemInfo.isWindowsXP());
                    LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
                    LookAndFeelFactory.installJideExtension(LookAndFeelFactory.OFFICE2003_STYLE);

                    // 设置默认字体
                    Font font = new Font("宋体", Font.PLAIN, 12);
                    Enumeration<?> keys = UIManager.getDefaults().keys();
                    while (keys.hasMoreElements()) {
                        Object key = keys.nextElement();
                        Object value = UIManager.get(key);
                        if (value instanceof FontUIResource) {
                            UIManager.put(key, font);
                        }
                    }

                    DataSourceManager.INSTANCE.initDataSources(this.getClass().getClassLoader().getResourceAsStream(
                            "datasource.xml"));
                    MAIN_FRAME = new MainMtrWindow();
                    MAIN_FRAME.setVisible(true);
                    MAIN_FRAME.toFront();

                    SERIAL = new SimpleSerial();
                    SERIAL.init();
                    SERIAL.addSerialEventListener(MAIN_FRAME);

                    SmsSender.INSTANCE.initService();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
    }
}
